<template>
  <el-form
    :show-message="false"
    :hide-required-asterisk="true"
    :model="fromdata"
    label-width="160px"
    label-position="right"
    ref="fromdata"
    :rules="rules"
  >
    <el-row>
      <el-form-item
        label="每一小时工时换算金额:"
        prop="dictValue"
      >
        <el-input
          v-model="fromdata.dictValue"
          style="width: 220px"
          clearable
          placeholder="请输入"
        >
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
    </el-row>
    <el-row> 设置系统工时与工时费的计算比列；【例：1工时=100元】 </el-row>
    <el-row>
      <el-col
        :span="24"
        align="right"
      >
        <el-button
          type="primary"
          @click="onSubmit"
        >保存</el-button>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
// import {statusData} from '@/api/after-sale/systemManage/project'
import { addDict, updateDict, dictSetValueByKey } from "@/api/after-sale/dictionary";
import { getDict, getStoreId, getServerDict } from "@/utils/index";
export default {
  components: {},
  name: "DialogDataForm",
  props: {},
  data () {
    return {
      fromdata: {
        dictKey: "项目1小时换算金额", //字典类别
        dictValue: "", //字典值
        storeId: getStoreId(), //门店id
      },
      rules: {
        dictValue: [
          {
            required: true,
            message: "请输入项目1小时换算金额",
            trigger: "blur",
          },
        ],
      },
      dictKey: {},
      type: "",
    };
  },
  async created () {

    let data = await getServerDict('项目1小时换算金额');
    this.fromdata.dictValue = data[0].dictValue;
    // if (!this.dictKey["项目1小时换算金额"]) {
    //   this.type = "add";
    // } else {
    //   this.type = "edit";
    //   this.fromdata.dictValue = this.dictKey["项目1小时换算金额"][0].value;
    // }
  },
  methods: {
    onSubmit () {
      this.$refs["fromdata"].validate((valid) => {
        if (valid) {
          this.saveData();
        } else {
          return false;
        }
      });
    },
    async saveData () {
      const { success } = await dictSetValueByKey(this.fromdata.dictKey, this.fromdata.dictValue);
      // const { success } =
      //   this.type == "edit"
      //     ? await updateDict(this.fromdata)
      //     : await addDict(this.fromdata);
      if (success) {
        this.$message({
          message: "操作成功",
          type: "success",
        });
        this.$emit("close", true);
      } else {
        this.$message.error("操作失败");
      }
    },
  },
};
</script>
